#define DIS 0   //(def 1)DIS 5 map in kPa  DIS 6 debug DIS 1 Tinjectors in us x100 DIS 7 dispaly adc chanels
                //DIS 8 print som in_parm parameters
//#define MON_RS 4// 1 send all over uart 2 olnly base 4 by default

#if DIS != 0
void out_dat (void)
{
    unsigned int8 i;
    // unsigned int8 eng_stat; 

    //   kb_temp=kb_read();
    lcd_clear();
    // if (acc_timer){eng_stat='!';}
    // else {eng_stat=' ';}

#if DIS==1
//============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14
    printf(lcd_putch,"XY %1X%1X Pw %2u%%",mapt,obt,pul);
    lcd_goto(0x0C);
    if (pw_acc) {
        //(acc_timer)
        printf(lcd_putch,"%3u",pw_acc);
    } else if (pw_corr_per!=100) {
        printf(lcd_putch,"c%3u",pw_corr_per);
    }
    lcd_goto(0x10);
    //printf(lcd_putch,"KB %2u",kb_temp);
    printf(lcd_putch,"E %Lu",out_parm.vecurr1);//out_parm.vecurr1
    //printf(lcd_putch,"%4.3Ld",max_dot);//out_parm.mapdot);
    //printf(lcd_putch,"%4.3Ld",in_parm.mapdot_table[0]);
//============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
    printf(lcd_putch,"n %3Lu",oboroti/10);
    for(i=0 ; i<barob ; i++) {
        lcd_putch(0x05);
    }
    lcd_putch(barobd);
    lcd_goto(0x4E);
    //printf (lcd_putch,"D%5Ld",diff);

    if (ad_ch[1]) {
    	printf (lcd_putch,"t%5Ld",out_parm.clt/10);
    	//printf (lcd_putch,"t%3.1w",out_parm.clt);
    } else {
        printf (lcd_putch,"No Pow");
    }
    //printf (lcd_putch,"t%5Lu",ad_ch[2]);
    //printf (lcd_putch,"t%Ld",pw_corr);
//============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"%% %3u",bar_percent);
    //printf(lcd_putch,"%3u%u",barv,barvd);
    for(i=0 ; i<barv ; i++) {
        lcd_putch(0x05);
    }
    lcd_putch(barvd);
    lcd_goto(0x22);               //28 end row
    printf (lcd_putch,"M%5Lu",k_pa);
//============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"T%4Lu",((unsigned int32)timeinj*TMR_0_P)/(ICLK/10)); //old time int8 ICLK/10!!!!!1111
    //printf("T%4Lu c%4Lu",(timeinj*TMR_0_P)/(ICLK/10),timeinj);
    // printf(lcd_putch,"T%4u",bar_p_inj);
    for(i=0 ; i<barinj ; i++) {
        lcd_putch(0x05);
    }
    lcd_putch(barinjd);
    lcd_goto(0x62);
    if (deb_inj) {
        printf(lcd_putch"c%5Lu",flow_tst_couter);
    } else {
        printf (lcd_putch,"V%5.1w",out_parm.batt);
    }
#elif DIS==5
//============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14
    printf(lcd_putch,"XY %u%u Pw %2u%%",mapt,obt,pul);
    lcd_goto(0x0F);
    printf(lcd_putch,"KB %2u",kb_temp);
//============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
    printf(lcd_putch,"n %3Lu",oboroti/10);
    for(i=0 ; i<barob ; i++) {
        lcd_putch(0x05);
    }
    lcd_putch(barobd);
    lcd_goto(0x4E);
    printf (lcd_putch,"D%5Ld",diff);
//============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"%% %3u",bar_percent);
    for(i=0 ; i<barv ; i++) {
        lcd_putch(0x05);
    }
    lcd_putch(barvd);
    lcd_goto(0x22);               //28 end row
    printf (lcd_putch,"M%5Lu",k_pa);
//============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"T%4u",timeinj);
    //    printf(lcd_putch,"T%Lu",tmp);
    for(i=0 ; i<barinj ; i++) {
          lcd_putch(0x05);
    }
    lcd_putch(barinjd);
    lcd_goto(0x62);
    printf (lcd_putch,"V%5.2w",adct);
#elif DIS==6
    //   lcd_goto(0x54);               //start row 68 end
    //printf(lcd_putch,"T%4Lu",timeinj);
    //   printf(lcd_putch,"%Lu",tmp);
    //for(i=0 ; i<barinj ; i++)
       {
      //    lcd_putch(0x05);
       }
    //lcd_putch(barinjd);
#elif DIS==7
//============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14
    printf(lcd_putch,"ch0:%Lu",ad_ch[0]);
    //============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
    printf(lcd_putch,"ch1:%Lu",ad_ch[1]);
    //============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"ch2:%Lu",ad_ch[2]);
    //============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"ch3:%Lu",ad_ch[3]);

#elif DIS==8
    //============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14

    printf(lcd_putch,"%Lu T %u",in_parm.baud,timeinj);

    //============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
     printf(lcd_putch,"R %Lu v %Lu %u %u",in_parm.ReqFuel,out_parm.pw1,in_parm.PrimeP,in_parm.InjPWMDty);
    //============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"%u %u %u %u",in_parm.ve_table[0][0][0],in_parm.ve_table[0][0][1],in_parm.ve_table[0][0][2],in_parm.ve_table[0][0][3]);
    //============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"%u %u %u %u",in_parm.ve_table[0][1][0],in_parm.ve_table[0][1][1],in_parm.ve_table[0][1][2],in_parm.ve_table[0][1][3]);
}
#else
#error   dis_ 1 to 8
#endif
#else
#warning "out_dat() - function is disabled OK"
#endif
void rs_out_data ()
{
    //++++++++++++++++++++++++ RS 232 ++++++++++++++++++++++++++++++++++
#ifdef MON_RS
#if MON_RS == 1
    printf("%4Lu %2u %3Lu %3u %u %u %u %Lu\r",oboroti,pul,adct,timeinj,mapt,obt,kb_temp,flow_tst_couter);
#elif MON_RS == 2
    printf("%4Lu %2u %3Lu %3u %u %u\r",oboroti,pul,adct,timeinj,mapt,obt);
#elif MON_RS == 3
    printf("%4Lu %4Lu %4Lu %4Lu\r",ad_ch[0],ad_ch[1],ad_ch[2],ad_ch[3]);
#elif MON_RS == 4
    /*  if(cmd_rcv)
    {
    printf("\r%s\r",rs_string);
    //puts(rs_string);
    printf("\rVal: %u\r",table_read(&fmap,1));
    //  table_write(&fmap,2,0xaa);
    cmd_rcv=0;
    }*/
    if (rs_string[0]=='d') {
        printf("Rev:%4Lu Pw:%2u Adc:%3Lu Time:%3Lu X:%u Y:%u\r",oboroti,pul,adct,timeinj,mapt,obt);
    }
    if (rs_string[0]=='z') {
        rs_string[0]=0;
        printf("\n%4Lu %4Lu %4Lu %4Lu\r",ad_ch[0],ad_ch[1],ad_ch[2],ad_ch[3]);
    }

#elif MON_RS == 5
    if (rs_string[0]=='d') {
        printf("acc_time: %u step:%u timer:%u \n\r",pw_acc,tail_off_step,tail_off_timer);
    }
#endif

#endif
    //        delay_ms(150);
}

void display_adc (void)
{
    lcd_clear();
    //============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14
    printf(lcd_putch,"ch0: %Lu %Lu %Lu", in.ad_ch[0], in.ad_ch[1], in.ad_ch[2]);
    //============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
    printf(lcd_putch,"ch3: %Lu %Lu %Lu", in.ad_ch[3], in.ad_ch[4], in.ad_ch[5]);
    //============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"ch6: %Lu %Lu", in.ad_ch[6], in.ad_ch[7]);
    //============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"ch8: %Lu %Lu", in.ad_ch[8], in.ad_ch[9]);
}

void display_env (void)
{
    lcd_clear();
    //============== Row1 oboroti digit an bar==================
    lcd_goto(0x00);                        //start row end 14
    printf(lcd_putch,"Kpa %Lu", in.in.map);
    //============== Row2 time==================
    lcd_goto(0x40);                        //start row end 54
    printf(lcd_putch,"Fu %f L Out: %u", in.f_count, out.kb_button);
    //============== Row3 map==================
    lcd_goto(0x14);               //start row
    printf(lcd_putch,"TPS %Lu%%", in.in.tps);
    //============== Row4 obototi==================
    lcd_goto(0x54);               //start row 68 end
    printf(lcd_putch,"PW %Lu us", in.in.pw1);
} 

void dispaly_ign_time (int8 mode_d)
{   
    lcd_clear();
    switch (mode_d) {
    case IGN_1:
        //============== Row1 ==================
        lcd_goto(0x00);                        //start row end 14
        printf(lcd_putch,"In0 %Lu", in.offset_ign_chanel[COUNT_1]);
        //============== Row2 ==================
        lcd_goto(0x40);                        //start row end 54
        printf(lcd_putch,"In1 %Lu To %lu", in.offset_ign_chanel[COUNT_2],
                                                    in.time);
        //============== Row3 ==================
        lcd_goto(0x14);               //start row
        printf(lcd_putch,"In2 %Lu Ti %lu",in.offset_ign_chanel[COUNT_3],
                                                    in.ign_timer_in);
        //============== Row4 ==================
        lcd_goto(0x54);               //start row 68 end
        printf(lcd_putch,"In3 %Lu", in.offset_ign_chanel[COUNT_4]);
        break;
     case IGN_2:
        //============== Row1 ==================
        lcd_goto(0x00);                        //start row end 14
        printf(lcd_putch,"coil %Lu", in.spark_timer_tick);
        //============== Row2 ==================
        lcd_goto(0x40);                        //start row end 54
        printf(lcd_putch,"n/a");
        //============== Row3 ==================
        lcd_goto(0x14);               //start row
        printf(lcd_putch,"In3 %Lu %3.1w", in.offset_ign_chanel[COUNT_4],
                                                    in.ign_table_out);
        //============== Row4 ==================
        lcd_goto(0x54);               //start row 68 end
        printf(lcd_putch,"In3 %Lu %3.1w", in.offset_ign_chanel[COUNT_4],
                                                    in.ign_table_out);
        break;
    case IGN_3:
        //============== Row1 ==================
        lcd_goto(0x00);                        //start row end 14
        printf(lcd_putch,"To %Lu  Tp %Lu", in.time, in.time_1);
        //============== Row2 ==================
        lcd_goto(0x40);                        //start row end 54
        printf(lcd_putch, "Rpm%5Lu  %4Ld", in.in.rpm, in.diff);
        //============== Row3 ==================
        lcd_goto(0x14);               //start row
        printf(lcd_putch,"%4Ld %4Ld %4Ld %4Ld",
                            in.offset_ign_chanel[COUNT_1],
                            in.offset_ign_chanel[COUNT_2],
                            in.offset_ign_chanel[COUNT_3],
                            in.offset_ign_chanel[COUNT_4]);
        //============== Row4 ==================
        lcd_goto(0x54);               //start row 68 end
        printf(lcd_putch,"%4Ld %4Ld %4Ld %4Ld",
                        in.offset_ign_chanel[COUNT_1] - 1800,
                        in.offset_ign_chanel[COUNT_2] - 3600,
                        in.offset_ign_chanel[COUNT_3] - 5400,
                        in.offset_ign_chanel[COUNT_4] - 7200);
        break;
    default:
        printf(lcd_putch,"%u %u", mode_d, display_mode);
        break;
    }
    return;
}

void new_dis (mode_dis mode) 
{
    int i=0;
    
    lcd_clear();
    switch (mode) {
        case MODE_DEF:
        default:

//============== Row1 oboroti digit an bar==================
            lcd_goto(0x00);                        //start row end 14
            printf(lcd_putch, "XY %1X%1X Pw %2u%%", in.mapt, in.obt, pul);
            lcd_goto(0x0C);

            if (in.pw_acc) {
                //(acc_timer)
                printf(lcd_putch, "%3u", in.pw_acc);
            } else if (in.pw_corr_per!=100) {
                    printf(lcd_putch, "c%3u", in.pw_corr_per);
            }

            lcd_goto(0x10);
            printf(lcd_putch, "E %Lu", in.in.vecurr1);//out_parm.vecurr1

//============== Row2 time==================
            lcd_goto(0x40);                        //start row end 54
            printf(lcd_putch, "n %3Lu", in.in.rpm/10);

            for(i = 0; i < barob; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barobd);
            lcd_goto(0x4E);

            if (in.ad_ch[1]) {
                printf (lcd_putch, "t%5Ld", in.in.clt/10);
            } else {
                printf (lcd_putch, "No Pow");
            }

//============== Row3 map==================
            lcd_goto(0x14);               //start row
            printf(lcd_putch, "%% %3u", in.bar_percent);

            for(i = 0; i < barv; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barvd);
            lcd_goto(0x22);               //28 end row
            printf (lcd_putch, "M%5Lu", in.in.map);

//============== Row4 obototi==================
            lcd_goto(0x54);               //start row 68 end
            printf(lcd_putch, "T%4Lu", ((unsigned int32)in.timeinj*TMR_0_P)/(ICLK/10)); //old time int8 ICLK/10!!!!!1111

            for(i = 0; i < barinj; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barinjd);
            lcd_goto(0x62);

            if (in.flow_tst_couter) {
                printf(lcd_putch, "c%5Lu", in.flow_tst_couter);
            } else {
                printf (lcd_putch, "V%5.1w", in.in.batt);
            }
            break;

        case MODE_FUEL:

//============== Row1 oboroti digit an bar==================
            lcd_goto(0x00);                        //start row end 14

            printf(lcd_putch, "XY%1X%1X L%1.3f", in.mapt, in.obt, in.f_count);

            //printf(lcd_putch,"P %Lu us F %f L", pw_count, f_count);

            lcd_goto(0x0C);

            if (in.pw_acc) {
                //(acc_timer)
                printf(lcd_putch,"%3u",in.pw_acc);
            }else if (in.pw_corr_per!=100) {
                    printf(lcd_putch, "c%3u", in.pw_corr_per);
            }

            lcd_goto(0x10);
            printf(lcd_putch, "E %Lu", in.in.vecurr1);//out_parm.vecurr1

//============== Row2 time==================
            lcd_goto(0x40);                        //start row end 54
            printf(lcd_putch, "n %3Lu", in.in.rpm/10);

            for(i=0; i < barob; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barobd);
            lcd_goto(0x4E);

            if (in.ad_ch[1]) {
                printf (lcd_putch, "t%5Ld", in.in.clt/10);
            } else {
                printf (lcd_putch, "No Pow");
            }
//============== Row3 map==================
            lcd_goto(0x14);               //start row
            printf(lcd_putch, "%% %3u", in.bar_percent);

            for(i = 0; i < barv; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barvd);
            lcd_goto(0x22);               //28 end row
            printf (lcd_putch, "M%5Lu", in.in.map);
//============== Row4 obototi==================
            lcd_goto(0x54);               //start row 68 end
            printf(lcd_putch, "T%4Lu", ((unsigned int32)in.timeinj*TMR_0_P)/(ICLK/10)); //old time int8 ICLK/10!!!!!1111

            for(i = 0; i < barinj; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barinjd);
            lcd_goto(0x62);

            if (in.flow_tst_couter) {
                printf(lcd_putch, "c%5Lu", in.flow_tst_couter);
            } else {
                printf (lcd_putch, "V%5.1w", in.in.batt);
            }
            break;

        case MODE_FUEL_NEW:

//============== Row1 oboroti digit an bar==================
            lcd_goto(0x00);                        //start row end 14
            if (!in.cycles) {
                printf(lcd_putch, "XY%1X%1X L%1.3f", in.mapt, in.obt, in.f_count);
            } else {
                printf(lcd_putch, "XY%1X%1X CW%u", in.mapt, in.obt, in.cycles);
            }

            //printf(lcd_putch,"P %Lu us F %f L", pw_count, f_count);

            lcd_goto(0x0C);

            if (in.pw_acc) {
                //(acc_timer)
                printf(lcd_putch, "%3u", in.pw_acc);
            } else if (in.pw_corr_per != 100) {
                    printf(lcd_putch, "c%3u", in.pw_corr_per);
            }

            lcd_goto(0x10);
            printf(lcd_putch, "E %Lu", in.in.vecurr1);//out_parm.vecurr1

//============== Row2 time==================
            lcd_goto(0x40);                        //start row end 54
            printf(lcd_putch, "n %3Lu", in.in.rpm/10);

            for(i=0 ; i<barob ; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barobd);
            lcd_goto(0x4E);

            if (in.ad_ch[1]) {
                printf (lcd_putch, "t%5Ld", in.in.clt/10);
            } else {
                printf (lcd_putch, "No Pow");
            }

//============== Row3 map==================
            lcd_goto(0x14);               //start row
            printf(lcd_putch, "%% %3u", in.bar_percent);

            for(i = 0; i < barv; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barvd);
            lcd_goto(0x22);               //28 end row
            printf (lcd_putch, "M%5Lu", in.in.map);

//============== Row4 obototi==================
            lcd_goto(0x54);               //start row 68 end
            if (!in.ign_power_up) {
                printf(lcd_putch, "T%4Lu", ((unsigned int32)in.timeinj*TMR_0_P)/(ICLK/10)); //old time int8 ICLK/10!!!!!1111
            } else {
                printf(lcd_putch, "Tp%3Lu", ((unsigned int32)in.timeinj_crank*TMR_0_P)/(ICLK/10));
            }
                
            for(i = 0; i < barinj; i++) {
                lcd_putch(0x05);
            }

            lcd_putch(barinjd);
            lcd_goto(0x62);

            if (in.flow_tst_couter) {
                printf(lcd_putch, "c%5Lu", in.flow_tst_couter);
            } else {
                printf (lcd_putch, "V%5.1w", in.in.batt);
            }
            break;

    }
    rs_out_data();
}

